package com.lisn.roomlib;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;

import com.lisn.roomlib.FileInfo.FileInfo;
import com.lisn.roomlib.FileInfo.FileInfoDao;
import com.lisn.roomlib.FileInfo.FileInfoDatabase;

import java.util.List;

/**
 * @author : lishan
 * @e-mail : cnlishan@163.com
 * @date : 2020/8/14 4:40 PM
 * @desc :
 */
class FileRepository {

    private final FileInfoDao fileInfoDao;
    private final LiveData<List<FileInfo>> allFileInfos;

    public FileRepository() {
        fileInfoDao = FileInfoDatabase.get().getFileInfoDao();
        allFileInfos = fileInfoDao.getAlphabetizedFileInfo();
    }

    LiveData<List<FileInfo>> getAllFileInfos() {
        return allFileInfos;
    }

    void save(final FileInfo fileInfo) {
        FileInfoDatabase.databaseWriteExecutor.execute(new Runnable() {
            @Override
            public void run() {

                fileInfoDao.save(fileInfo);
            }
        });
    }
}
